package com.project.webpage.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.project.webpage.dto.*;
import com.project.webpage.mapper.GjxlYbMapper;
import com.project.webpage.service.GjxlYbService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;

@Service
public class GjxlYbServiceImpl implements GjxlYbService {

    @Resource
    private GjxlYbMapper gjxlYbMapper;

    @Override
    @DS("master")
    public List<PassengerDto> getPassengerListForPage(SearchByMonthParam param) {
        return gjxlYbMapper.selectPassengerListByUid(param);
    }

    @Override
    @DS("master")
    public List<PassengerDto> getPassengerZlxlListForPage(SearchByMonthParam param) {
        return gjxlYbMapper.selectPassengerZlxlListByUid(param);
    }

    @Override
    @DS("master")
    public List<PassengerDto> getPassengerFeaturelListForPage(SearchByMonthParam param) {
        return gjxlYbMapper.selectPassengerFeatureListByUid(param);
    }

    @Override
    @DS("master")
    public List<PassengerBcDto> getPassengerBcListForPage(SearchByMonthParam param) {
        return gjxlYbMapper.selectPassengerBcListByUid(param);
    }

    @Override
    @DS("master")
    public List<PassengerZjDto> getPassengerZjListForPage(SearchByMonthParam param) {
        return gjxlYbMapper.selectPassengerZjListByUid(param);
    }

    @Override
    @DS("master")
    public List<PassengerNhDto> getPassengerNhListForPage(SearchByMonthParam param) {
        List<PassengerNhDto> list = gjxlYbMapper.selectPassengerNhListByUid(param);
        if(list != null && !list.isEmpty()){
            list.forEach(l->{

                //百公里柴油能耗
                Double nh_cy100 = StringUtils.isBlank(l.getYylc()) || "0".equals(l.getYylc())?0.0:
                        new BigDecimal(l.getNh_cy()).divide((new BigDecimal(l.getYylc()).divide(new BigDecimal(100))),
                                2, RoundingMode.HALF_UP).doubleValue();
                //百公里客流
                Double quantity100 = StringUtils.isBlank(l.getYylc()) || "0".equals(l.getYylc())?0.0:
                        new BigDecimal(l.getQuantity()).divide((new BigDecimal(l.getYylc()).divide(new BigDecimal(100))),
                                2, RoundingMode.HALF_UP).doubleValue();
                l.setNh_cy100(nh_cy100);
                l.setQuantity100(quantity100);

            });
        }
        return  list ;
    }

    @Override
    @DS("master")
    public List<PassengerXlqsDto> getPassengerXlqsListForPage(SearchByMonthParam param) {
        return gjxlYbMapper.selectPassengerXlqsListByUid(param);
    }

    @Override
    @DS("master")
    public List<CompanyNhDto> getCompanyNhListForPage(SearchByMonthParam param) {
        return gjxlYbMapper.selectCompanyNhListByUid(param);
    }

    @Override
    @DS("master")
    public List<CompanyIncomeDto> getCompanyIncomeListForPage(SearchByMonthParam param) {
        return gjxlYbMapper.selectCompanyIncomeListByUid(param);
    }

    @Override
    @DS("master")
    public List<CompanyXlqsNhDto> getCompanyXlqsNhListForPage(SearchByMonthParam param) {
        return gjxlYbMapper.selectCompanyXlqsNhListByUid(param);
    }

    @Override
    @DS("master")
    public List<PassengerCompareDto> getPassengerCompareListForPage(SearchByMonthParam param) {
        return gjxlYbMapper.selectPassengerCompareListByUid(param);
    }

    @Override
    @DS("master")
    public List<BusNhDto> getBusNhListForPage(SearchByMonthParam param) {
        return gjxlYbMapper.selectBusNhListByUid(param);
    }

    @Override
    @DS("master")
    public List<PassengerChangeIncomeDto> getPassengerChangeIncomeListForPage(SearchByMonthParam param) {
        return gjxlYbMapper.selectPassengerChangeIncomeListByUid(param);
    }
}